
#include	"SysConfig.h"
#include	"Define.h"

#ifdef  USER_WATCHDOG
extern unsigned char	ucCPU_WatchDog_Timer50msec;
#endif

#ifdef  LC786XXX
extern unsigned char ucDRV_LC786XXX_BusyTimer50msec;
#endif

extern unsigned char ucTask_Timer5msec;

#ifdef  LC786XXX_AUDIO
extern unsigned char	ucKEY_EncVolKey_Timer5msec;
#endif
extern unsigned char	ucPWR_AccMute_Timer5msec;
extern unsigned short	usPWR_AccSequence_Timer5msec;
extern unsigned short	usMENU_Timer100msec;
extern unsigned char	ucLC786XXX_USB_Detect_Timer10msec;
extern unsigned short	ucLC786XXX_Process_10msecTimer;
extern unsigned char	ucLC786XXX_MediaStatusCheck_10msecTimer;
extern unsigned char	ucLC786XXX_GetText_10msecTimer;
extern unsigned char	ucLC786XXX_ErrorSeq_100msec;
extern unsigned short  usLC786XXX_InitUSB_10mecTimer;

extern unsigned char	ucFUNC_Timer10msec;
extern unsigned short 	usLC786XXX_Update_10msecTimer;
extern unsigned char	usDISP_TempDispMode_Timer50msec;
extern unsigned char	ucDISP_Blink_Timer50msec;
extern unsigned char	ucDISP_CurrentDisplay_Timer50msec;
extern unsigned short	ucDISP_Scroll_Timer50msec;
extern unsigned char	ucDISP_FolderName_Timer50msec;
extern unsigned char	ucDISP_FileName_Timer50msec;

extern unsigned short	usTuner_ModeSeq_Timer5msec;
extern unsigned char	ucTuner_Scan_Timer50msec;
extern unsigned char	ucAUDIO_BeepOut_Timer5msec;

#ifdef  BLUETOOTH
extern unsigned short	usBT_Pair_Timer50msec;
extern unsigned short	usBT_ProcessSeq_Timer50msec;
extern unsigned short	usBT_AutoConnect_Timer100msec;
extern unsigned char	ucMV_HF_AudioStatus_Timer50msec;
extern unsigned char	ucBT_PBAP_Download_Timer50msec;
#endif
extern unsigned char ucKEY_ShortKey_Timer5msec;
extern unsigned short usKEY_LongKey_Timer10msec;
extern unsigned char ucKEY_Change_Timer5msec;

#ifdef  HERO
extern unsigned char	ucHERO_InitSeq_Timer10msec;
#endif
#ifdef  ATOMIC
extern unsigned char	ucATOMIC_BootSeq_Timer10msec;
#endif

#ifdef  ST7565P
extern unsigned char	ucST7565P_Seq_Timer5msec;
#endif

#ifdef  CD
extern unsigned char 	ucDISP_CD_ICON_Timer5msec;
#endif

extern unsigned char	ucPWR_BackUp_Timer5msec;
extern unsigned char	ucKEY_Rmc_Timer5msec;
extern unsigned char ucKEY_RmcInvalid_Timer5msec;
extern unsigned char ucPWR_Antenna_Timer50msec;

#ifdef  AV_CONTROLLER
extern unsigned short ucAVC_Process_Timer5msec;
#endif
#ifdef  AUTO_GUIDE
extern unsigned short usAG_Process_Timer10msec;
#endif

#ifdef  DOT_SCROLL
extern unsigned short usDISP_DotScroll_Timer5msec;
#endif

#ifdef  ZYLE_LOGO
extern unsigned char ucDISP_LogoActive_Timer100msec;
#endif
#ifdef  FILE_SEARCH
extern unsigned char ucLC786_GetFileName_Timer10msec;
#endif
extern unsigned short usAUDIO_TelMute_Timer100msec;

#define	DEC_TIMER(X)	if  (X!=0) --X

unsigned char ucUI_TIMER_5msecDiv;

void UI_TIMER_5msec_Local(unsigned short Times)
{
	unsigned short i;

	for(i = 0; i < Times; ++i)
	{
		while(ucTask_Timer5msec)
		{
		};
		ucTask_Timer5msec = 1;
	}
}

void UI_TIMER_5msec(void)
{
	#ifdef  CD
	DEC_TIMER(ucDISP_CD_ICON_Timer5msec);
	#endif
	#ifndef  ATOMIC
	DEC_TIMER(ucAUDIO_BeepOut_Timer5msec);
	#endif
	DEC_TIMER(ucKEY_ShortKey_Timer5msec);
	DEC_TIMER(ucKEY_Change_Timer5msec);
	#ifdef  ST7565P
	DEC_TIMER(ucST7565P_Seq_Timer5msec);
	#endif
	DEC_TIMER(usPWR_AccSequence_Timer5msec);
	DEC_TIMER(ucPWR_BackUp_Timer5msec);
	DEC_TIMER(ucPWR_AccMute_Timer5msec);
#ifdef  LC786XXX_AUDIO
	DEC_TIMER(ucKEY_EncVolKey_Timer5msec);
#endif
	DEC_TIMER(usTuner_ModeSeq_Timer5msec);
	DEC_TIMER(ucKEY_Rmc_Timer5msec);
	DEC_TIMER(ucKEY_RmcInvalid_Timer5msec);
#ifdef  DOT_SCROLL
	DEC_TIMER(usDISP_DotScroll_Timer5msec);
#endif
	#ifdef  AV_CONTROLLER
	DEC_TIMER(ucAVC_Process_Timer5msec);
	#endif
}

void UI_TIMER_10msec(void)
{
	DEC_TIMER(ucFUNC_Timer10msec);
	DEC_TIMER(ucLC786XXX_Process_10msecTimer);
	#ifdef  HERO
	DEC_TIMER(ucHERO_InitSeq_Timer10msec);
	#endif
	#ifdef  ATOMIC
	DEC_TIMER(ucATOMIC_BootSeq_Timer10msec);
	#endif
	DEC_TIMER(usKEY_LongKey_Timer10msec);
	#ifdef  LC786XXX
	DEC_TIMER(ucLC786XXX_GetText_10msecTimer);
	DEC_TIMER(usLC786XXX_Update_10msecTimer);
	DEC_TIMER(ucLC786XXX_USB_Detect_Timer10msec);
	DEC_TIMER(ucLC786XXX_MediaStatusCheck_10msecTimer);
	DEC_TIMER(usLC786XXX_InitUSB_10mecTimer);
	#endif
	#ifdef  AUTO_GUIDE
	DEC_TIMER(usAG_Process_Timer10msec);
	#endif
	#ifdef  FILE_SEARCH
	DEC_TIMER(ucLC786_GetFileName_Timer10msec);
	#endif
}

void UI_TIMER_50msec(void)
{
	DEC_TIMER(usDISP_TempDispMode_Timer50msec);
	DEC_TIMER(ucDISP_Blink_Timer50msec);
	DEC_TIMER(ucTuner_Scan_Timer50msec);
	DEC_TIMER(ucDISP_CurrentDisplay_Timer50msec);
#ifdef  BLUETOOTH
	DEC_TIMER(usBT_Pair_Timer50msec);
	DEC_TIMER(usBT_ProcessSeq_Timer50msec);
	DEC_TIMER(ucMV_HF_AudioStatus_Timer50msec);
	DEC_TIMER(ucBT_PBAP_Download_Timer50msec);
#endif
	DEC_TIMER(ucDISP_Scroll_Timer50msec);
#ifdef  USER_WATCHDOG
	DEC_TIMER(ucCPU_WatchDog_Timer50msec);
#endif
	DEC_TIMER(ucDISP_FolderName_Timer50msec);
	DEC_TIMER(ucDISP_FileName_Timer50msec);

#ifdef  LC786XXX	
	DEC_TIMER(ucDRV_LC786XXX_BusyTimer50msec);
#endif
}

void UI_TIMER_100msec(void)
{	
#ifdef  BLUETOOTH
	DEC_TIMER(usBT_AutoConnect_Timer100msec);
#endif
	DEC_TIMER(usMENU_Timer100msec);
	DEC_TIMER(ucLC786XXX_ErrorSeq_100msec);
#ifdef  ZYLE_LOGO
	DEC_TIMER(ucDISP_LogoActive_Timer100msec);
#endif
	DEC_TIMER(usAUDIO_TelMute_Timer100msec);
}

void UI_TIMER_Main(void)	// 5msec
{
	++ucUI_TIMER_5msecDiv;
	
	if  ((ucUI_TIMER_5msecDiv % 2) == 0)
	{
		UI_TIMER_10msec();
	}
	if  ((ucUI_TIMER_5msecDiv % (50/5)) == 0)
	{
		UI_TIMER_50msec();
	}
	if  ((ucUI_TIMER_5msecDiv % (100/5)) == 0)
	{
		UI_TIMER_100msec();
		ucUI_TIMER_5msecDiv = 0;
	}
	UI_TIMER_5msec();
}

